package com.mutual.reins.interf.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mutual.reins.interf.entity.*;
import com.mutual.reins.interf.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author 86152
 */
@Api("XXX调用接口")
@RestController
@RequestMapping("/reins")
public class ReinsEndorConller {
    @Autowired
    private IReinsEndorUnitService iReinsEndorUnitService;
    @Autowired
    private IReinsEndorItemService iReinsEndorItemService;
    @Autowired
    private IReinsEndorCoinsService iReinsEndorCoinsService;
    @Autowired
    private IReinsEndorFeeService iReinsEndorFeeService;
    @Autowired
    private IReinsEndorPlanService iReinsEndorPlanService;
    @Autowired
    private IGeneratePrppApplyDangerUnitService iGeneratePrppApplyDangerUnitService;
    @Autowired
    private IReinsEndorCoinsService reinsEndorCoinsService;
    @Autowired
    private IReinsEndorFeeService reinsEndorFeeService;
    @Autowired
    private IReinsEndorItemService reinsEndorItemService;
    @ApiOperation("获取是否第一次批改")
    @GetMapping("/ReinsEndorItem/{policyNo}")
    public void getReinsEndorItem(@PathVariable("policyNo") String policyNo) {
        QueryWrapper<ReinsEndorItem> qw = new QueryWrapper<>();
        qw.eq("POLICYNO", policyNo);
        qw.orderByAsc("ITEMKINDNO");
        List<ReinsEndorItem> reinsEndorItemList = iReinsEndorItemService.list(qw);
        for (ReinsEndorItem reinsEndorItem : reinsEndorItemList) {
            System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" + reinsEndorItem.getItemKindNo());
        }
    }
    @ApiOperation("获取是否第一次批改")
    @GetMapping("/ReinsEndorUnit/{cerTiNo}")
    public void getReinsEndorUnit(@PathVariable("cerTiNo") String cerTiNo) {
        QueryWrapper<ReinsEndorUnit> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ENDORNO", cerTiNo);
        ReinsEndorUnit reinsEndorUnit = iReinsEndorUnitService.getOne(queryWrapper);
        System.out.println(reinsEndorUnit.getAmount());
    }
    @ApiOperation("获取是否第一次批改")
    @GetMapping("/ReinsUnit/{cerTiNo}")
    public void deleteReinsEndorUnit(@PathVariable("cerTiNo") String cerTiNo) {
        Map<String, Object> columnMap = new HashMap<String, Object>(16) {{
            put("ENDORNO", cerTiNo);
        }};
        reinsEndorItemService.removeByMap(columnMap);
        reinsEndorCoinsService.removeByMap(columnMap);
        reinsEndorFeeService.removeByMap(columnMap);
        iReinsEndorUnitService.removeByMap(columnMap);
    }
    @ApiOperation("获取是否第一次批改")
    @GetMapping("/ReinsEndorInFo/{cerTiNo}")
    public void testReinsEndorInFo(@PathVariable("cerTiNo") String cerTiNo) {
        Map<String, Object> columnMap = new HashMap<String, Object>(16) {{
            put("ENDORNO", cerTiNo);
        }};
        String endorNo = "";
        ReinsEndorInterfDto reinsEndorInterfDto = new ReinsEndorInterfDto();
        //unit表
        List<ReinsEndorUnit> reinsEndorUnitList = iReinsEndorUnitService.listByMap(columnMap);
        for (ReinsEndorUnit reinsEndorUnit : reinsEndorUnitList) {
            reinsEndorInterfDto.setReinsEndorUnitDto(reinsEndorUnit);
            endorNo = reinsEndorUnit.getEndorNo();
        }
        //item表
        List<ReinsEndorItem> reinsEndorItems = iReinsEndorItemService.listByMap(columnMap);
        reinsEndorInterfDto.setReinsEndorItemDto(reinsEndorItems);
        //coins表
        List<ReinsEndorCoins> reinsEndorCoins = iReinsEndorCoinsService.listByMap(columnMap);
        reinsEndorInterfDto.setReinsEndorCoinsDto(reinsEndorCoins);

        //plan表
        List<ReinsEndorPlan> reinsEndorPlans = iReinsEndorPlanService.listByMap(columnMap);
        reinsEndorInterfDto.setReinsEndorPlanDto(reinsEndorPlans);
        //fee表
        List<ReinsEndorFee> reinsEndorFees = iReinsEndorFeeService.listByMap(columnMap);
        reinsEndorInterfDto.setReinsEndorFeeDto(reinsEndorFees);
        reinsEndorInterfDto.setCerTiNo(endorNo);
        reinsEndorInterfDto.setCerTiType("E");
        JSONObject json = JSONUtil.parseObj(reinsEndorInterfDto, false);
        System.out.println(json.toStringPretty());
        //1、使用JSONObject
//        JSONObject json = JSONObject.fromObject();
//        //2、使用JSONArray
//        JSONArray array= new JSONArray(reinsEndorInterfDto);
//        String strJson=json.toString();
//        String strArray=array.toString();
//        System.out.println("strJson:"+strJson);
//        System.out.println("strArray:"+strArray);
        ReinsStatusDto reinsStatusDto = iGeneratePrppApplyDangerUnitService.generateReinsEndorseInfo(reinsEndorInterfDto);
        System.out.println("&&&&&&&&&OK=================OK&&&&&&&&&&&&" + reinsStatusDto.getStatus());
    }
}
